package com.learn;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author: liyf
 * @create: 2025-02-12 19:27
 **/
public class MergeFile {

    public static void main(String[] args) {

        File file1 =new File("E:\\Videos\\蜡笔小新\\蜡笔小新第5季\\1 - 要笑,是园长先生哦 - 1.flv");
        File file2 =new File("E:\\Videos\\蜡笔小新\\蜡笔小新第5季\\1 - 要笑,是园长先生哦 - 2.flv");
        File file3 =new File("E:\\Videos\\蜡笔小新\\蜡笔小新第5季\\1 - 要笑,是园长先生哦.flv");

        // 合并视频文件
        try (FileInputStream fis1 = new FileInputStream(file1);
             FileInputStream fis2 = new FileInputStream(file2);
             FileOutputStream fos = new FileOutputStream(file3)) {

            // 读取并写入第一个视频文件
            byte[] buffer = new byte[1024];
            int length;
            while ((length = fis1.read(buffer)) > 0) {
                fos.write(buffer, 0, length);
            }

            // 读取并写入第二个视频文件
            while ((length = fis2.read(buffer)) > 0) {
                fos.write(buffer, 0, length);
            }

            System.out.println("视频合并完成，输出文件路径为: " + file3);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
